//首页
declare var $:any;
declare var wx: any;
declare var WeixinJSBridge : any;
import { Component,OnInit } from '@angular/core';
import { UserComponent } from '../../components/user/user.component';

import { stampDataService } from '../../services/stampData.service';
import { ConfigService } from '../../services/config.service';
import { stampProgressService } from '../../services/stampProgress.service';

import { encry,decry } from "../../services/base64.service";
import axios from 'axios';
@Component({
  selector: 'activity',
  templateUrl: './activity.component.html',
  styleUrls: ['./activity.component.css']
})
export class ActivityComponent {
    title = 'app';

    //规则弹窗
    rulesHide = true;
    //邮戳详情弹窗
    stampHide = true;

    //服务器资源头
    imgPre = "../../wxassets/twoyear/";

    //彩带图片
    ribbonImg = this.imgPre + "assets/images/ribbon.png";

    //邮戳列表
    stampList = [
        {
            imgSrc:this.imgPre + "assets/images/logo/1_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/2_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/3_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/4_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/5_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/6_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/7_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/8_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/9_s_g.png",
            own:0
        },
        {
            imgSrc:this.imgPre + "assets/images/logo/10_s_g.png",
            own:0
        }
    ];

    //邮戳个数
    stamp_num = 0;

    //集邮是否完成
    finished = false;

    //邮戳详情相关信息
    stamp_name = "";
    stamp_src = "";
    stamp_desc = ""
    stamp_link = "";
    linkHide = false;

    //用户信息
    user_name = (localStorage.getItem("name")?localStorage.getItem("name"):"小镇居民");
    user_phone = localStorage.getItem("phone");

    constructor(
        private StampDataService:stampDataService,
        private configService: ConfigService,
        private stampProService:stampProgressService
    ){}
    ngOnInit(){
        var self = this;

        //动画
        self.animation();
        $("body").css("position","static");

        //获取用户集邮进度显示
        self.stampProService.getStampPro(localStorage.getItem("phone")).then((res)=>{
            console.log(res);

            if(res.data.code == 0){
                
                var list = res.data.msg;
                var count = 0;
                var i = 0;
                for(let k in list){
                    let n = i+1;
                    
                    if(list[k]!=""){
                        self.stampList[i].imgSrc = this.imgPre + "assets/images/logo/"+n+"_s.png";
                        self.stampList[i].own = 1;
                        count++;
                    }else{
                        self.stampList[i].imgSrc = this.imgPre + "assets/images/logo/"+n+"_s_g.png";
                        self.stampList[i].own = 0;
                    }
                    
                    i++;
                }
                self.stamp_num = count;
                if(res.data.state == 0){
                    self.finished = true;
                }
            }
            else if(res.data.code == 1){
                alert("请到现场扫码参与活动哦~");
            }
        }).catch((err)=>{
            alert("出错啦！");
        });
        
    }

    

    

    //查看邮戳函数
    checkStamp(i){
        var stampData = this.StampDataService.getStampInfo(i);
        this.stamp_name = stampData.name;
        this.stamp_src = stampData.logoSrc;
        this.stamp_desc = stampData.desc;
        if(stampData.link == ""){
            this.linkHide = true;
        }else{
            this.linkHide = false;
            this.stamp_link = stampData.link;
        }
    	this.stampHide = false;
    }

    //查看规则函数
    rules_btn(){
    	this.rulesHide = false;
    }

    //关闭规则
    closeRules(){
    	this.rulesHide = true;
    }

    //关闭邮戳详情
    closeStamp(){
        this.stampHide = true;
    }

    //跳转分享页面
    share_btn(){
        var self = this;
        // this.router.navigate(["/report"])

        //加密phone和name
        var phone2 = encry(self.user_phone);
        var name2 = encry(self.user_name);
        window.location.href = "http://yxbsve.mmarket.com/index.php?c=wechat&a=report&phone=" +phone2+"&name="+name2;
        
    }

    //动画效果
    animation(){
        $(".ribbonImg").enter("zoomIn");
        $(".titleBox").enter("zoomIn");
    }




}
